package com.zjeav.lingjiao.ui.home.Find;

import com.zjeav.lingjiao.base.baseBean.Find;
import com.zjeav.lingjiao.base.baseBean.Result;
import com.zjeav.lingjiao.base.listener.CommonListener;
import com.zjeav.lingjiao.base.service.FindItemService;
import com.zjeav.lingjiao.base.tools.ObservableServiceTool;
import com.zjeav.lingjiao.base.tools.RetrofitInstance;

import io.reactivex.Observable;
import io.reactivex.Observer;
import retrofit2.Retrofit;

public class FindPresenter implements CommonListener {
    private FindContract.FindView findView;

    public FindPresenter(FindContract.FindView findView) {
        this.findView = findView;
    }

    public void getFindDetail(int id) {
        Retrofit retrofit = RetrofitInstance.getJsonTokenInstance();
        FindItemService itemService = retrofit.create(FindItemService.class);
        ObservableServiceTool.getResult((Observable) itemService.getFind(id), 0, this);
    }

    @Override
    public void OnSuccess(Result result, int type) {
        if (type == 0) {
            this.findView.ShowFindDetail((Find) result.getData());
        }
    }

    @Override
    public void OnFailure(Throwable throwable, int type) {
        if (type == 0) {
            this.findView.ShowError(throwable);
        }
    }
}
